package com.example.mail.accountservice.filter;

import com.alibaba.druid.util.Utils;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <p>
 * 去除druid监控登录页面中的广告
 * </p>
 *
 * @author chang.zhou
 * @version 1$
 * @date Created in 2022/2/18 0:03
 */
@WebFilter(urlPatterns = "/druid/js/common.js")
public class RemoveAdFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        String text = Utils.readFromResource("support/http/resources/js/common.js");
        text = text.replace("this.buildFooter();", "");
        ((HttpServletResponse) servletResponse).setHeader("Content-Type","text/javascript;charset=utf-8");
        servletResponse.getWriter().write(text);
    }
}
